package com.techsoul.module.accounting.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.module.accounting.pojo.param.MaterialBuyPriceSaveParam;
import com.techsoul.module.accounting.pojo.param.MaterialBuyPriceSearchParam;
import com.techsoul.module.accounting.service.IMaterialBuyPriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.Date;

/**
 * 供应商采购价格配置基础，用于配置价格，产生最后付款结算。 Controller
 *
 * @author liuen
 * @date 2021-04-11
 */
@Api(tags = "供应商采购价格配置基础，用于配置价格，产生最后付款结算。")
@RestController
@RequestMapping("/accounting/materialBuyPrice")
public class MaterialBuyPriceController {

    @Autowired
    private Result result;

    @Autowired
    private IMaterialBuyPriceService service;

    @ApiOperation("新增")
    @Log(title = "供应商采购价格配置基础，用于配置价格，产生最后付款结算。", operationType = OperationTypeEnum.INSERT)
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody MaterialBuyPriceSaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @Log(title = "供应商采购价格配置基础，用于配置价格，产生最后付款结算。", operationType = OperationTypeEnum.DELETE)
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @Log(title = "供应商采购价格配置基础，用于配置价格，产生最后付款结算。", operationType = OperationTypeEnum.UPDATE)
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:update')")
    @PutMapping
    public Result update(@Valid @RequestBody MaterialBuyPriceSaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody MaterialBuyPriceSearchParam params) {
        return result.success(this.service.findAllList(params));
    }

    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody MaterialBuyPriceSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAllList(params, current, pageSize));
    }

    @ApiOperation("导入模板")
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:update')")
    @PostMapping("/importTemplate")
    public Result importTemplate() {
        return result.success(this.service.importTemplate());
    }

    @ApiOperation("导入")
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:update')")
    @PostMapping("/importData")
    public Result importData(String storeId, Date applyDate, MultipartFile file) {
        return result.success(this.service.importData(storeId, applyDate, file));
    }

    @ApiOperation("导入")
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:update')")
    @PostMapping("/getByMapId/{id}")
    public Result getByMapId(String mapId) {
        return result.success(this.service.getByMapId(mapId));
    }
    @ApiOperation("导入模板")
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:update')")
    @PostMapping("/importExistSpuTemplate")
    public Result importExistSpuTemplate() {
        return result.success(this.service.importExistSpuTemplate());
    }

    @ApiOperation("导入")
    @PreAuthorize("hasAnyAuthority('accounting:materialBuyPrice:update')")
    @PostMapping("/importExistSpuData")
    public Result importExistSpuData(String mallId,MultipartFile file) {
        return result.success(this.service.importExistSpuData(mallId,file));
    }
}
